package com.dv.web.controller.systemevent;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.enums.BusinessType;
import com.dv.driverless.domain.InfoWarning;
import com.dv.driverless.service.IInfoWarningService;
import com.dv.common.utils.poi.ExcelUtil;
import com.dv.common.core.page.TableDataInfo;

/**
 * 报警信息Controller
 *
 * @author ruoyi
 * @date 2023-04-06
 */
@RestController
@RequestMapping("/systemevent/warning")
public class InfoWarningController extends BaseController
{
    @Autowired
    private IInfoWarningService infoWarningService;

    /**
     * 查询报警信息列表
     */
    @PreAuthorize("@ss.hasPermi('systemevent:warning:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoWarning infoWarning)
    {
        startPage();
        List<InfoWarning> list = infoWarningService.selectInfoWarningList(infoWarning);
        return getDataTable(list);
    }

    /**
     * 导出报警信息列表
     */
    @PreAuthorize("@ss.hasPermi('systemevent:warning:export')")
    @Log(title = "报警信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoWarning infoWarning)
    {
        List<InfoWarning> list = infoWarningService.selectInfoWarningList(infoWarning);
        ExcelUtil<InfoWarning> util = new ExcelUtil<InfoWarning>(InfoWarning.class);
        util.exportExcel(response, list, "报警信息数据");
    }

    /**
     * 获取报警信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('systemevent:warning:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(infoWarningService.selectInfoWarningById(id));
    }

    /**
     * 新增报警信息
     */
    @PreAuthorize("@ss.hasPermi('systemevent:warning:add')")
    @Log(title = "报警信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoWarning infoWarning)
    {
        return toAjax(infoWarningService.insertInfoWarning(infoWarning));
    }

    /**
     * 修改报警信息
     */
    @PreAuthorize("@ss.hasPermi('systemevent:warning:edit')")
    @Log(title = "报警信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoWarning infoWarning)
    {
        return toAjax(infoWarningService.updateInfoWarning(infoWarning));
    }

    /**
     * 删除报警信息
     */
    @PreAuthorize("@ss.hasPermi('systemevent:warning:remove')")
    @Log(title = "报警信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(infoWarningService.deleteInfoWarningByIds(ids));
    }
}
